iT邦幫忙

2024 iThome 鐵人賽

DAY 21
0
Software Development

開發都來不及了還做什麼測試系列 第 21

Day21. 利用Katalon Studio進行自動化測試

  • 分享至 

  • xImage
  •  

利用Katalon Studio for functional testing, regression testing
可以寫程式也可以不寫,可以用它來寫test cases、執行test cases和分析你的測試結果。

https://katalon.com/

https://ithelp.ithome.com.tw/upload/images/20240914/20108631TbcYKEDJWL.png

可以整合CI/CD, JIRA, GITHUB等
下載並安裝Katalon

開啟軟體
https://ithelp.ithome.com.tw/upload/images/20240914/201086316IUPbcM0Ol.png

https://ithelp.ithome.com.tw/upload/images/20240914/20108631A7pnVoKDXb.png

新增project
File -> New -> Project
MyFirstProject

https://ithelp.ithome.com.tw/upload/images/20240914/201086318ePRZhwG18.png

https://ithelp.ithome.com.tw/upload/images/20240914/20108631zcvYAZfrga.png

Project -> Settings
https://ithelp.ithome.com.tw/upload/images/20240914/20108631vgLfw8P8OE.png

Take Screenshot when execution failed

https://ithelp.ithome.com.tw/upload/images/20240914/20108631RMh2BcpN0C.png

record & spy
https://ithelp.ithome.com.tw/upload/images/20240914/20108631MiXYUBKJ2l.png

  • You record the steps and then execute them in spy

Writing test case

https://ithelp.ithome.com.tw/upload/images/20240914/201086313fnAq4ZXN5.png

https://ithelp.ithome.com.tw/upload/images/20240914/20108631b5D63ALzB4.png

https://katalon-demo-cura.herokuapp.com/
測試Katalon提供的sample網站

有兩種模式:Manual、Script
https://ithelp.ithome.com.tw/upload/images/20240914/20108631soXCwRNKr4.png

切換到Manual

Add
https://ithelp.ithome.com.tw/upload/images/20240914/20108631YGBEdrT275.png
有很多action可以選

切換到groovy script

新增一行

WebUI.back()

https://ithelp.ithome.com.tw/upload/images/20240914/20108631KCKxh6d5Qw.png

再切回Manual

則會發現多了一個back action
https://ithelp.ithome.com.tw/upload/images/20240914/20108631xGrGGOV2w5.png

所以這兩個是一樣的可以互通

開始撰寫

  1. 移除掉現有所有Item

  2. 新增open browser的action
    https://ithelp.ithome.com.tw/upload/images/20240914/201086319NZZk0SP1R.png

  3. Input
    url = https://katalon-demo-cura.herokuapp.com/
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631QfGn5flBVm.png

  4. 執行 -> 確認初始化成功
    會自動打開頁面
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631gbsZ8Jlrgt.png

  5. 新增測試步驟
    這次使用Script示範
    WebUI.verifyMatch(WebUI.getWindowTitle(), 'CURA Healthcare Service', false)
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631xRb4lJpk2e.png

  6. 切回Manual檢查
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631CeIhZLVOGV.png

  7. 新增click action
    WebUI.click(findTestObject)

  8. 利用spy web來選取物件
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631Kh3xhXqPUR.png

  9. Mouse over navbar menu and send ALT + ` key and go to login option and go on
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631zJrhEbI27a.png

  10. Change Object Name

    • SideHamburgerMenu
    • LoginButton
      https://ithelp.ithome.com.tw/upload/images/20240914/20108631VPcKBM5nK3.png
  11. 可以用Verify and Highlight來檢查是否有抓正確

  12. Save
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631dczP3OLbQO.png

    https://ithelp.ithome.com.tw/upload/images/20240914/20108631h37xFqEayQ.png

  13. 將findTestObject改為 SideHamburgerMenu和LoginButton

    WebUI.click(findTestObject('Object Repository/Page_CURA Healthcare Service/SideHamburgerMenu'))
    WebUI.click(findTestObject('Object Repository/Page_CURA Healthcare Service/LoginButton'))
    

    https://ithelp.ithome.com.tw/upload/images/20240914/20108631P3U3pDldvn.png

  14. 新增close browser
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631awQY3WII22.png

  15. 執行
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631oG7XMlmxJU.png

Adding test cases to test suites

  1. Test Listeners -> New -> New Test Listeners
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631Iku4R9YXdl.png

    https://ithelp.ithome.com.tw/upload/images/20240914/20108631XOVCIsC9aU.png

  2. Listener Script
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631Ufg3thUbkO.png

  3. 將openBrowser的code移到 @BeforeTestSuite

    /**
     * Executes before every test suite starts.
     * @param testSuiteContext: related information of the executed test suite.
     */
    @BeforeTestSuite
    def sampleBeforeTestSuite(TestSuiteContext testSuiteContext) {
    	println testSuiteContext.getTestSuiteId()
    	WebUI.openBrowser('https://katalon-demo-cura.herokuapp.com/')
    }
    
  4. 將closeBrowser的code移到 @AfterTestSuite

    /**
     * Executes after every test suite ends.
     * @param testSuiteContext: related information of the executed test suite.
     */
    @AfterTestSuite
    def sampleAfterTestSuite(TestSuiteContext testSuiteContext) {
    	println testSuiteContext.getTestSuiteId()
    	WebUI.closeBrowser()
    }
    
  5. 檢視更改成果
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631msGKJGJUG2.png

  6. 新增Test Suite
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631QvLEoyQJg8.png

    https://ithelp.ithome.com.tw/upload/images/20240914/201086318agceO7djP.png

  7. 將Navigation新增到test suite中
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631ur0l2bxzlb.png

    https://ithelp.ithome.com.tw/upload/images/20240914/20108631l0xbz9srDI.png

  8. 執行test suite
    https://ithelp.ithome.com.tw/upload/images/20240914/20108631W7DjFzx8gQ.png

Take screenshot

在Test case最後新增一行

WebUI.takeScreenshot('screenshots/screen1.png')

執行test suite
https://ithelp.ithome.com.tw/upload/images/20240914/20108631LsmXX9ygtq.png

可以從資料夾中找到screenshot
https://ithelp.ithome.com.tw/upload/images/20240914/201086312DmBdEjXTX.png

https://ithelp.ithome.com.tw/upload/images/20240914/20108631pBccjGv7Yg.png

可以從Results看到測試結果
https://ithelp.ithome.com.tw/upload/images/20240914/20108631CQFTUf1CcZ.png

本文章同步發布於個人blogger


上一篇
Day20. Selenium IDE
下一篇
Day22. 兼職測試工程師接案網站
系列文
開發都來不及了還做什麼測試30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言